/*
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.

Note:
Each of the array element will not exceed 100.
The array size will not exceed 200
*/
class Solution {
public:
    bool canPartition(vector<int>& nums) {
        int cnt = accumulate(nums.begin(), nums.end(), 0);
        if(cnt%2 != 0)
            return false;
        int target=cnt/2;
        vector<bool>dp(target+1, false);
        dp[0]=true;
        for(int i=0; i<nums.size(); ++i)
        {
            for(int j=target; j>=nums[i]; --j)
            {
                dp[j] = dp[j] || dp[j-nums[i]];
            }
        }
        return dp[target];
    }
    
    
};